package com.Service.Impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.Dao.BaseDaoI;
import com.Entity.Orders;
import com.Service.OrderService;

@Service("orderservice")
public class OrderServiceImpl extends BaseServiceImpl<Orders> implements OrderService {
	
	@Autowired
	private BaseDaoI<Orders> ordersdao;
	List<Orders> orderslistlist=new ArrayList<Orders>();
	
	
	@Override
	public List<Orders> findByDataId(int dataId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("dataId", dataId);
		
		String hql = "from Orders t where t.dataId = :dataId";
		try {
			orderslistlist=this.ordersdao.find(hql, params);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return orderslistlist;
	}
	
	@Override
	public List<Orders> findByUserId(int userId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userId", userId);
		
		String hql = "from Orders t where t.userId = :userId";
		try {
			orderslistlist=this.ordersdao.find(hql, params);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return orderslistlist;	
	}
	
	@Override
	public List<Orders> findByMotherId(int motherId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("motherId", motherId);
		
		String hql = "from Orders t where t.motherId = :motherId";
		try {
			orderslistlist=this.ordersdao.find(hql, params);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return orderslistlist;	
	}
	
	@Override
	public List<Orders> getOrdersListByMotherId(int MotherId,int page,int rows) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("MotherId", MotherId);		
		String hql="from Orders t where t.motherId=:MotherId and t.orderContent is not null order by orderUploadTime DESC";
		return ordersdao.find(hql, params, page, rows);
}

}
